/*
 * @Descripttion: 
 * @version: 
 * @Author: sueRimn
 * @Date: 2021-03-09 17:20:49
 * @LastEditors: wenbin
 * @LastEditTime: 2021-05-31 13:21:55
 */
import request from './index';

function sendHttpRequest(requests) {
  return new Promise((resolve, reject) => {
    requests
      .then(response => {
        resolve(response)
      })
      .catch(error => {
        reject(error)
      });
  });
}

export function post(url, param, headers, other) {
  return sendHttpRequest(
    request({
      url: url,
      method: 'post',
      data: param ? param : '',
      headers,
      ...other
    })
  );
}

export function put(url, param, headers, other) {
  return sendHttpRequest(
    request({
      url: url,
      method: 'put',
      data: param ? param : '',
      headers,
      ...other
    })
  );
}

export function deletes(url, param, headers, other) {
  return sendHttpRequest(
    request({
      url: url,
      method: 'delete',
      data: param ? param : '',
      headers,
      ...other
    })
  );
}

export function get(url, param, headers, other) {
  // alert(BASE_API)
  // if(arguments[2] === void 0){ prefixUrl = BASE_API }
  let timestamp = (new Date()).getTime()
  let newUrl = url
  let newUrl2 = ''

  if (!!window.ActiveXObject || "ActiveXObject" in window) {
    let newUrlArr = newUrl.split('?')
    if (newUrlArr.length > 1) {
      newUrl2 = `${newUrl}&ieStamp=${timestamp}`
    } else {
      newUrl2 = `${newUrl}?ieStamp=${timestamp}`
    }
  } else {
    newUrl2 = newUrl
  }

  return sendHttpRequest(
    request({
      url: newUrl2,
      method: 'get',
      params: param ? param : '',
      headers,
      ...other
    })
  );
}

export function post_param(url, param, headers, other) {
  return sendHttpRequest(
    request({
      url: url,
      method: 'post',
      params: param ? param : '',
      headers,
      ...other
    })
  );
}